package no.netlight.gotogate;

import java.util.HashMap;

/**
 * @author Mats Ormehaug
 */
public class Airport {
	private String code;
    private String name;
    private HashMap<String,String[][]> heavyTraffic;
    private HashMap<String,String> walkToGateDomestic;
    private HashMap<String,String> security;
    private HashMap<String,String> walkToGateInternational;
    private HashMap<String,String> baggageDrop;
    private HashMap<String,String> checkIn;
    
    public Airport(){
    	initStatistics();
    }
    public Airport(String code){
    	this.code = code;
    	initStatistics();
    }

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	@Override
	public String toString() {
		return "Airport [code=" + code + ", name=" + name + "]";
	}
	
	public void initStatistics(){
		heavyTraffic = new HashMap<String,String[][]>();
		String[][] times = {{"0500","0900"},{"1300","1700"}};
		heavyTraffic.put("2", times);
		times = new String[1][2];
		times[0][0] = "0500";
		times[0][1] = "0900";
		heavyTraffic.put("3", times);
		times = new String[2][2];		
		times[0][0] = "0500";
		times[0][1] = "0900";
		times[1][0] = "1300";
		times[1][1] = "1700";
		heavyTraffic.put("4", times);
		times = new String[2][2];		
		times[0][0] = "0500";
		times[0][1] = "0900";
		times[1][0] = "1300";
		times[1][1] = "2100";
		heavyTraffic.put("5", times);
		times = new String[2][2];		
		times[0][0] = "0500";
		times[0][1] = "0900";
		times[1][0] = "1300";
		times[1][1] = "2100";
		heavyTraffic.put("6", times);
		times = new String[1][2];
		times[0][0] = "0500";
		times[0][1] = "0900";
		heavyTraffic.put("7", times);
		times = new String[1][2];
		times[0][0] = "1300";
		times[0][1] = "2100";
		heavyTraffic.put("1", times);
		walkToGateDomestic = new HashMap<String,String>();
		walkToGateDomestic.put("heavy", "5");
		walkToGateDomestic.put("light", "5");
		walkToGateInternational = new HashMap<String,String>();
		walkToGateInternational.put("heavy", "20");
		walkToGateInternational.put("light", "10");
		security = new HashMap<String,String>();
		security.put("heavy", "15");
		security.put("light", "10");
		baggageDrop = new HashMap<String,String>();
		baggageDrop.put("heavy", "10");
		baggageDrop.put("light", "5");
		checkIn = new HashMap<String,String>();
		checkIn.put("heavy", "15");
		checkIn.put("light", "5");
	}
	/**
	 * 
	 * @param departureTime
	 * 			"HHMM" indicating departure time of the flight
	 * @param departureDay
	 * 			3 letters indicating the day, first letter uppercase, 
	 * 			rest lowercase, i.e. "Mon","Sat" etc
	 * @param destination
	 * 			domestic or international flight, i.e. {"Domestic", "International"}
	 * @return
	 * 			a string containing number of minutes it is likely to 
	 * 			take to walk to the gate
	 */
	public String getTimeWalkingToGate(String departureTime, String departureDay,String destination){
		if(destination.equals("Domestic")){
			if(isHeavyTraffic(departureTime,departureDay)){
				return walkToGateDomestic.get("heavy");
			}
			return walkToGateDomestic.get("light");
		} else {
			if(isHeavyTraffic(departureTime,departureDay)){
				return walkToGateInternational.get("heavy");
			}
			return walkToGateInternational.get("light");
		}
	}
	/**
	 * 
	 * @param departureTime
	 * 			"HHMM" indicating departure time of the flight
	 * @param departureDay
	 * 			3 letters indicating the day, first letter uppercase, 
	 * 			rest lowercase, i.e. "Mon","Sat" etc
	 * @return
	 * 			a string containing number of minutes it is likely to 
	 * 			take to go through security
	 */
	public String getTimeSecurityCheck(String departureTime, String departureDay){
		if(isHeavyTraffic(departureTime,departureDay)){
			return security.get("heavy");
		}
		return security.get("light");

	}
	/**
	 * 
	 * @param departureTime
	 * 			"HHMM" indicating departure time of the flight
	 * @param departureDay
	 * 			3 letters indicating the day, first letter uppercase, 
	 * 			rest lowercase, i.e. "Mon","Sat" etc
	 * @return
	 * 			a string containing number of minutes it is likely to 
	 * 			take to drop off bags
	 */
	public String getTimeBagDrop(String departureTime, String departureDay){
		if(isHeavyTraffic(departureTime,departureDay)){
			return baggageDrop.get("heavy");
		}
		return baggageDrop.get("light");

	}
	/**
	 * 
	 * @param departureTime
	 * 			"HHMM" indicating departure time of the flight
	 * @param departureDay
	 * 			3 letters indicating the day, first letter uppercase, 
	 * 			rest lowercase, i.e. "Mon","Sat" etc
	 * @return
	 * 			a string containing number of minutes it is likely to 
	 * 			take to check in
	 */
	public String getTimeCheckIn(String departureTime, String departureDay){
		if(isHeavyTraffic(departureTime,departureDay)){
			return checkIn.get("heavy");
		}
		return checkIn.get("light");
	}
	
	public boolean isHeavyTraffic(String departureTime, String departureDay){
		boolean heavy = false;
		String[][] traffic = heavyTraffic.get(departureDay);
		for(String[] times : traffic){
			if(Integer.parseInt(departureTime) >= Integer.parseInt(times[0]) &&
					Integer.parseInt(departureTime) < Integer.parseInt(times[1])){
				heavy = true;
				break;
			}
		}
		return heavy;
	}
	
}
